package com.service.impl;

import com.entity.Auction;
import com.entity.Commodity;
import com.entity.UserInfo;
import com.mapper.AuctionMapper;
import com.service.AuctionService;
import com.util.KeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Service
public class AuctionServiceImpl implements AuctionService {
    @Autowired
    private AuctionMapper auctionMapper;

    @Override
    public List<Auction> getBidLog(String commId) {
        Commodity commodity = auctionMapper.queryCommName(commId);
        return auctionMapper.queryAuctionLog(commodity.getCommname());
    }

    @Override
    public void addAuctionBid(String userId, String commId, BigDecimal amount) {
        UserInfo userInfo = auctionMapper.queryUserInfo(userId);
        String username = userInfo.getUsername();
        Commodity commodity = auctionMapper.queryCommName(commId);
        String commname = commodity.getCommname();
        Auction auction = new Auction(KeyUtil.genUniqueKey(),username,amount,commname,new Date(),new Date());
        auctionMapper.insertAuctionBid(auction);
    }
}
